export const setItem = (key, value) => {
  if (typeof value === 'object') {
    sessionStorage.setItem(key, JSON.stringify(value))
  } else {
    sessionStorage.setItem(key, value)
  }
}

export const getItem = (key: string) => {
  const data = sessionStorage.getItem(key)
  if (data === null) {
    return ''
  }
  try {
    return JSON.parse(data)
  } catch {
    return data
  }
}

export const setLocalItem  = (key, value) => {
  if (typeof value === 'object') {
    localStorage.setItem(key, JSON.stringify(value))
  } else {
    localStorage.setItem(key, value)
  }
}

export const getLocalItem = (key: string) => {
  const data = localStorage.getItem(key)
  if (data === null) {
    return ''
  }
  try {
    return JSON.parse(data)
  } catch {
    return data
  }
}

export const removeLocalItem = (key: string) => {
  localStorage.removeItem(key)
}

export const removeItem = (key: string) => {
  sessionStorage.removeItem(key)
}